package org.wu.framework.inner.lazy.orm.spring.config;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Role;
import org.wu.framework.lazy.orm.core.config.prop.LazyDataSourceAttribute;
import org.wu.framework.lazy.orm.database.lambda.LazyBaseDDLOperation;
import org.wu.framework.lazy.orm.database.lambda.LazyBaseDQLOperation;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.cure.*;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.cure.lazy.LazySchemaCure;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.cure.lazy.LazyTableColumnCure;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.cure.lazy.LazyTableCure;

import java.util.List;

/**
 * describe :
 *
 * @author : Jia wei Wu
 * @version 1.0
 * @date : 2023/1/12 19:59
 */
@ConditionalOnProperty(prefix = "spring.datasource", value = "url")
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class CureAutoConfiguration {

    /**
     * describe 表结构治愈
     *
     * @param lazyBaseDDLOperation DDL 语言
     * @param lazyBaseDQLOperation DQL 语言
     * @return TableCure
     * @author Jia wei Wu
     * @date 2023/1/12 20:01
     **/
//    @ConditionalOnBean(value = {DataSource.class, LazyBaseDDLOperation.class, LazyBaseDQLOperation.class})
    @Bean
    @ConditionalOnMissingBean(TableCure.class)
    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    public TableCure tableCure(LazyBaseDDLOperation lazyBaseDDLOperation, LazyBaseDQLOperation lazyBaseDQLOperation) {
        return new LazyTableCure(lazyBaseDDLOperation, lazyBaseDQLOperation);
    }

    /**
     * description:  表字段治愈
     *
     * @param lazyBaseDDLOperation
     * @param lazyBaseDQLOperation
     * @return
     * @author 吴佳伟
     * @date: 16.1.23 01:37
     */
//    @ConditionalOnBean(value = {DataSource.class, LazyBaseDDLOperation.class, LazyBaseDQLOperation.class})
    @Bean
    @ConditionalOnMissingBean(TableColumnCure.class)
    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    public TableColumnCure tableColumnCure(LazyBaseDDLOperation lazyBaseDDLOperation, LazyBaseDQLOperation lazyBaseDQLOperation) {
        return new LazyTableColumnCure(lazyBaseDDLOperation, lazyBaseDQLOperation);
    }

    /**
     * describe schema治愈
     *
     * @param
     * @return
     * @throws
     * @author Jia wei Wu
     * @date 2023/1/12 20:01
     **/
    @Bean
    @ConditionalOnMissingBean(SchemaCure.class)
    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    @ConditionalOnBean(LazyDataSourceAttribute.class)
    public SchemaCure schemaCure(LazyBaseDDLOperation lazyBaseDDLOperation) {
        return new LazySchemaCure(lazyBaseDDLOperation);
    }

    /**
     * describe 治愈适配器
     *
     * @param
     * @return
     * @throws
     * @author Jia wei Wu
     * @date 2023/1/12 20:01
     **/
    @Bean
    @ConditionalOnMissingBean(CureAdapter.class)
    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    public CureAdapter cureAdapter(List<Cure> cureList) {
        return new CureAdapter(cureList);
    }

}
